package lunchy.mvc.controllers;

import java.util.ArrayList;

import lunchy.data.interfaces.ILunchyMenuGroup;
import lunchy.data.interfaces.ILunchyMenuItem;
import lunchy.main.CLunchyApplication;
import lunchy.mvc.models.CLunchyMenuModel;
import lunchy.mvc.views.CLunchyLoginDialogView;
import lunchy.mvc.views.CLunchyMenuEditView;

public class CLunchyMenuController
{
	private CLunchyMenuModel model;
	
	public CLunchyMenuController()
	{	
		model = new CLunchyMenuModel();
	}

	public ArrayList<ILunchyMenuGroup> getMenuGroups()
	{
		return model.getMenuGroups();
	}
	
	public boolean saveOrder()
	{
		CLunchyApplication.getInstance().debug("[CLunchyMenuController] Start saving order...");
		
		boolean saveResult = false;
		
		// TODO Не очень нормально - не забыть спросить
		if(CLunchyApplication.getInstance().currentUser != null)
			saveResult = model.saveOrder();
		else
		{
			showLoginDialog();
			if(CLunchyApplication.getInstance().currentUser != null)
				saveResult = model.saveOrder();
		}
		
		CLunchyApplication.getInstance().debug("[CLunchyMenuController] End saving order...");
		
		return saveResult;
	}
	
	public void showLoginDialog()
	{
		new CLunchyLoginDialogView();
	}
	
	public void showMenuEditWindow()
	{
		new CLunchyMenuEditView();
		model.reloadMenu();
	}
	
	public void AddOrUpdateItemInOrder(ILunchyMenuItem item, Integer count)
	{
		model.AddOrUpdateItemInCurrentOrder(item, count);
	}
}
